#include "lolevel.h"
#include "platform.h"
#include "core.h"


static long *nrflag = (long*)0x6CE0;

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) sub_FFD39620_my(long p)
{
    asm volatile (
	    	"STMFD   SP!, {R4,R5,LR}\n"
	    	"LDR     R3, =0x73D34\n"
	    	"LDR     R5, =0x6CDC\n"
	    	"SUB     SP, SP, #4\n"
	    	"LDR     R1, =0xFFFFFFFF\n"
	    	"STR     R0, [R5]\n"
	    	"LDR     R0, [R3]\n"
	    	"BL      sub_FFC0FA60\n"
	    	"BL      sub_FFD3F438\n"
            "BL      wait_until_remote_button_is_released\n"
	    	"LDR     R0, [R0,#0x7C]\n"
	    	"BL      sub_FFD39594\n" // nr

	    	"BL      capt_seq_hook_set_nr\n"

	    	"LDR     R3, =0x6CE4\n"
		"LDR     R0, [R3]\n"
	    	"BL      sub_FFC8C088\n"

		"B	 sub_FFD3965C\n" // continue orig. func
    );
}

void __attribute__((naked,noinline)) sub_FFD364B0_my(long p)
{
    asm volatile (
                "STMFD   SP!, {R4,R5,LR}\n"
                "LDR     R5, [R0,#0xC]\n"
                "BL      sub_FFD3F1DC\n"
                "CMP     R0, #0\n"
                "BNE     1f\n"
                "BL      sub_FFD3F1E8\n"

"1:\n"
                "MOV     R0, R5\n"
                "BL      sub_FFD3842C\n"
                "TST     R0, #1\n"
                "MOV     R2, R5\n"
                "MOV     R1, #1\n"
                "BEQ     2f\n"
                "LDMFD   SP!, {R4,R5,LR}\n"
                "B       sub_FFD34A08\n"

"2:\n"
                "BL      sub_FFD74484\n"
                "BL      sub_FFD33DF4\n"
                "MOV     R4, R0\n"
                "BL      sub_FFC143A4\n"
                "ADD     R3, R5, R5,LSL#1\n"
                "ADD     R4, R4, R3,LSL#5\n"
                "STR     R0, [R4,#4]\n"
                "MOV     R0, R5\n"
                "BL      sub_FFD39E38\n" // ??
                "BL      sub_FFD38970\n" // tv related
                "BL      sub_FFD38910\n" // ??
                "MOV     R0, R5\n"
                "BL      sub_FFD39620_my\n" // make photo

		"BL      capt_seq_hook_raw_here\n"

                "MOV     R2, R5\n"
                "MOV     R1, #1\n"
                "BL      sub_FFD34A08\n" // save file ?
                "LDMFD   SP!, {R4,R5,LR}\n"
                "B       sub_FFD39820\n"
    );
}

void __attribute__((naked,noinline)) capt_seq_task()
{
	asm volatile (
                "STMFD   SP!, {R4,LR}\n"
                "SUB     SP, SP, #4\n"
                "MOV     R4, SP\n"
                "B       loc_FFD36A08\n"
// ---------------------------------------------------------------------------

"loc_FFD368B4:\n"
                "LDR     R2, [SP,#0xC-0xC]\n"
                "LDR     R3, [R2]\n"
                "MOV     R0, R2\n"
                "CMP     R3, #0x15\n"
                "LDRLS   PC, [PC,R3,LSL#2]\n"
                "B       loc_FFD369E0\n"
// ---------------------------------------------------------------------------
                ".long loc_FFD36924\n"
                ".long loc_FFD36930\n"
                ".long loc_FFD36938\n"
                ".long loc_FFD36948\n"
                ".long loc_FFD36940\n"
                ".long loc_FFD36950\n"
                ".long loc_FFD36958\n"
                ".long loc_FFD36964\n"
                ".long loc_FFD3696C\n"
                ".long loc_FFD36978\n"
                ".long loc_FFD36980\n"
                ".long loc_FFD36988\n"
                ".long loc_FFD36990\n"
                ".long loc_FFD36998\n"
                ".long loc_FFD369A0\n"
                ".long loc_FFD369AC\n"
                ".long loc_FFD369B4\n"
                ".long loc_FFD369BC\n"
                ".long loc_FFD369C4\n"
                ".long loc_FFD369D0\n"
                ".long loc_FFD369D8\n"
                ".long loc_FFD369F0\n"
// ---------------------------------------------------------------------------

"loc_FFD36924:\n"
                "BL      sub_FFD38088\n"
                "BL      shooting_expo_param_override\n"  // +
                "BL      sub_FFD34560\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36930:\n"
                "BL      sub_FFD364B0_my\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36938:\n"
                "BL      sub_FFD3841C\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36940:\n"
                "BL      sub_FFD37344\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36948:\n"
                "BL      sub_FFD373A0\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36950:\n"
                "BL      sub_FFD37590\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36958:\n"
                "BL      sub_FFD3817C\n"
                "BL      sub_FFD34560\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36964:\n"
                "BL      sub_FFD36598\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD3696C:\n"
                "BL      sub_FFD381E4\n"
                "BL      sub_FFD34560\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36978:\n"
                "BL      sub_FFD373A0\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36980:\n"
                "BL      sub_FFD38AA8\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36988:\n"
                "BL      sub_FFD38D30\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36990:\n"
                "BL      sub_FFD38DBC\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD36998:\n"
                "BL      sub_FFD38E74\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD369A0:\n"
                "MOV     R0, #0\n"
                "BL      sub_FFD38F24\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD369AC:"
                "BL      sub_FFD39074\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD369B4:\n"
                "BL      sub_FFD390E8\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD369BC:\n"
                "BL      sub_FFD391A0\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD369C4:\n"
                "MOV     R0, #1\n"
                "BL      sub_FFD38F24\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD369D0:\n"
                "BL      sub_FFD392A0\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD369D8:\n"
                "BL      sub_FFD392CC\n"
                "B       loc_FFD369EC\n"
// ---------------------------------------------------------------------------

"loc_FFD369E0:\n"
                "LDR     R0, =0xFFD36234\n"
                "MOV     R1, #0x2DC\n"
                "BL      sub_FFC03AD0\n"

"loc_FFD369EC:\n"
                "LDR     R2, [SP,#0xC-0xC]\n"

"loc_FFD369F0:\n"
                "LDR     R3, =0x73CBC\n"
                "LDR     R1, [R2,#4]\n"
                "LDR     R0, [R3]\n"
                "BL      sub_FFC0F8C4\n"
                "LDR     R0, [SP,#0xC-0xC]\n"
                "BL      sub_FFD362B0\n"

"loc_FFD36A08:\n"
                "LDR     R3, =0x73CC0\n"
                "MOV     R1, R4\n"
                "LDR     R0, [R3]\n"
                "MOV     R2, #0\n"
                "BL      sub_FFC10074\n"
                "TST     R0, #1\n"
                "BEQ     loc_FFD368B4\n"
                "MOV     R1, #0x24C\n"
                "LDR     R0, =0xFFD36234\n"
                "ADD     R1, R1, #1\n"
                "BL      sub_FFC03AD0\n"
                "BL      sub_FFC11610\n"
                "ADD     SP, SP, #4\n"
                "LDMFD   SP!, {R4,PC}\n"

    );
}

void __attribute__((naked,noinline)) exp_drv_task(){
 asm volatile(
                "STMFD   SP!, {R4-R8,LR}\n"
                "SUB     SP, SP, #0x14\n"
                "MOV     R7, SP\n"
                "B       loc_FFCE3148\n"
"loc_FFCE2E64:\n"
                "CMP     R2, #0x19\n"
                "BNE     loc_FFCE2E7C\n"
                "LDR     R0, [R12,#0x34]\n"
                "MOV     LR, PC\n"
                "LDR     PC, [R12,#0x30]\n"
                "B       loc_FFCE2EB4\n"
"loc_FFCE2E7C:\n"
                "SUB     R3, R2, #0x16\n"
                "CMP     R3, #1\n"
                "BHI     loc_FFCE2E94\n"
                "MOV     R0, R12\n"
                "BL      sub_FFCE2DFC\n"
                "B       loc_FFCE2EA4\n"
"loc_FFCE2E94:\n"
                "CMP     R2, #0x18\n"
                "BNE     loc_FFCE2EC0\n"
                "BL      sub_FFC97A1C\n"
                "BL      sub_FFC99894\n"
"loc_FFCE2EA4:\n"
                "LDR     R3, [SP,#0x0]\n"
                "LDR     R0, [R3,#0x34]\n"
                "MOV     LR, PC\n"
                "LDR     PC, [R3,#0x30]\n"
"loc_FFCE2EB4:\n"
                "LDR     R0, [SP,#0x0]\n"
                "BL      sub_FFCE114C\n"
                "B       loc_FFCE3148\n"
"loc_FFCE2EC0:\n"
                "CMP     R2, #0xC\n"
                "MOV     R8, #1\n"
                "BNE     loc_FFCE2F30\n"
                "LDR     R1, [R12,#0x24]\n"
                "ADD     R1, R1, R1,LSL#1\n"
                "ADD     R1, R12, R1,LSL#1\n"
                "ADD     R6, SP, #0xC\n"
                "SUB     R1, R1, #2\n"
                "MOV     R2, #6\n"
                "MOV     R0, R6\n"
                "BL      _memcpy\n"
                "LDR     R0, [SP,#0x0]\n"
                "BL      sub_FFCE2424\n"
                "LDR     R3, [SP,#0x0]\n"
                "LDR     R1, [R3,#0x24]\n"
                "LDR     R2, [R3,#0x34]\n"
                "ADD     R0, R3, #4\n"
                "MOV     LR, PC\n"
                "LDR     PC, [R3,#0x30]\n"
                "LDR     R0, [SP,#0x0]\n"
                "BL      sub_FFCE25A8\n"
                "LDR     R3, [SP,#0x0]\n"
                "ADD     R0, R3, #4\n"
                "LDR     R1, [R3,#0x24]\n"
                "LDR     R2, [R3,#0x3C]\n"
                "MOV     LR, PC\n"
                "LDR     PC, [R3,#0x38]\n"
                "B       loc_FFCE30F8\n"
"loc_FFCE2F30:\n"
                "SUB     R3, R2, #0xD\n"
                "CMP     R3, #1\n"
                "BHI     loc_FFCE2FB0\n"
                "ADD     R6, SP, #0xC\n"
                "ADD     R5, SP, #0x4\n"
                "MOV     R0, R12\n"
                "MOV     R1, R6\n"
                "MOV     R2, R5\n"
                "BL      sub_FFCE2624\n"
                "MOV     R4, R0\n"
                "CMP     R4, #3\n"
                "CMPNE   R4, #1\n"
                "BNE     loc_FFCE2F90\n"
                "LDR     R12, [SP,#0x0]\n"
                "MOV     R0, R5\n"
                "LDR     R1, [R12,#0x24]\n"
                "MOV     R2, R4\n"
                "LDR     R3, [R12,#0x34]\n"
                "MOV     LR, PC\n"
                "LDR     PC, [R12,#0x30]\n"
                "MOV     R1, R4\n"
                "LDR     R0, [SP,#0x0]\n"
                "BL      sub_FFCE2DDC\n"
                "B       loc_FFCE30F8\n"
"loc_FFCE2F90:\n"
                "LDR     R12, [SP,#0x0]\n"
                "MOV     R2, R4\n"
                "ADD     R0, R12, #4\n"
                "LDR     R1, [R12,#0x24]\n"
                "LDR     R3, [R12,#0x34]\n"
                "MOV     LR, PC\n"
                "LDR     PC, [R12,#0x30]\n"
                "B       loc_FFCE30F8\n"
"loc_FFCE2FB0:\n"
                "CMP     R2, #0x14\n"
                "BNE     loc_FFCE3004\n"
                "LDR     R1, [R12,#0x24]\n"
                "ADD     R1, R1, R1,LSL#1\n"
                "ADD     R1, R12, R1,LSL#1\n"
                "ADD     R6, SP, #0xC\n"
                "SUB     R1, R1, #2\n"
                "MOV     R2, #6\n"
                "MOV     R0, R6\n"
                "BL      _memcpy\n"
                "LDR     R0, [SP,#0x0]\n"
                "BL      sub_FFCE1EFC\n"
                "LDR     R3, [SP,#0x0]\n"
                "ADD     R0, R3, #4\n"
                "LDR     R1, [R3,#0x24]\n"
                "LDR     R2, [R3,#0x34]\n"
                "MOV     LR, PC\n"
                "LDR     PC, [R3,#0x30]\n"
                "LDR     R0, [SP,#0x0]\n"
                "BL      sub_FFCE2154\n"
                "B       loc_FFCE30F8\n"
"loc_FFCE3004:\n"
                "ADD     R6, SP, #0xC\n"
                "ADD     R1, R12, #4\n"
                "MOV     R0, R6\n"
                "MOV     R2, #6\n"
                "BL      _memcpy\n"
                "LDR     R12, [SP,#0x0]\n"
                "LDR     R3, [R12]\n"
                "MOV     R0, R12\n"
                "CMP     R3, #0x15\n"
                "LDRLS   PC, [PC,R3,LSL#2]\n"
                "B       loc_FFCE30E4\n"
                ".long loc_FFCE3088\n"
                ".long loc_FFCE3090\n"
                ".long loc_FFCE3098\n"
                ".long loc_FFCE3098\n"
                ".long loc_FFCE3088\n"
                ".long loc_FFCE3090\n"
                ".long loc_FFCE3098\n"
                ".long loc_FFCE3098\n"
                ".long loc_FFCE30B0\n"
                ".long loc_FFCE30B0\n"
                ".long loc_FFCE30D4\n"
                ".long loc_FFCE30DC\n"
                ".long loc_FFCE30E4\n"
                ".long loc_FFCE30E4\n"
                ".long loc_FFCE30E4\n"
                ".long loc_FFCE30A0\n"
                ".long loc_FFCE30A8\n"
                ".long loc_FFCE30BC\n"
                ".long loc_FFCE30C4\n"
                ".long loc_FFCE30C4\n"
                ".long loc_FFCE30E4\n"
                ".long loc_FFCE30CC\n"
"loc_FFCE3088:\n"
                "BL      sub_FFCE1628\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE3090:\n"
                "BL      sub_FFCE1764\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE3098:\n"
                "BL      sub_FFCE1894\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE30A0:\n"
                "BL      sub_FFCE1A68\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE30A8:\n"
                "BL      sub_FFCE1B70\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE30B0:\n"
                "BL      sub_FFCE1C34_my\n"  //---------->
                "MOV     R8, #0\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE30BC:\n"
                "BL      sub_FFCE1CF8\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE30C4:\n"
                "BL      sub_FFCE1DE0\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE30CC:\n"
                "BL      sub_FFCE21E4\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE30D4:\n"
                "BL      sub_FFCE22B8\n"
                "B       loc_FFCE30E0\n"
"loc_FFCE30DC:\n"
                "BL      sub_FFCE23A4\n"
"loc_FFCE30E0:\n"
                "LDR     R12, [SP,#0x0]\n"
"loc_FFCE30E4:\n"
                "ADD     R0, R12, #4\n"
                "LDR     R1, [R12,#0x24]\n"
                "LDR     R2, [R12,#0x34]\n"
                "MOV     LR, PC\n"
                "LDR     PC, [R12,#0x30]\n"
"loc_FFCE30F8:\n"
                "CMP     R8, #1\n"
                "BNE     loc_FFCE3120\n"
                "LDR     R1, [SP,#0x0]\n"
                "LDR     R3, [R1,#0x24]\n"
                "ADD     R3, R3, R3,LSL#1\n"
                "ADD     R1, R1, R3,LSL#1\n"
                "MOV     R0, R6\n"
                "SUB     R1, R1, #2\n"
                "BL      sub_FFCE14E0\n"
                "B       loc_FFCE3140\n"
"loc_FFCE3120:\n"
                "MOV     R0, #1\n"
                "MOV     R1, R0\n"
                "MOV     R2, R0\n"
                "BL      sub_FFCE1484\n"
                "MOV     R0, #1\n"
                "MOV     R1, R0\n"
                "MOV     R2, R0\n"
                "BL      sub_FFCE15A0\n"
"loc_FFCE3140:\n"
                "LDR     R0, [SP,#0x0]\n"
                "BL      sub_FFCE114C\n"
"loc_FFCE3148:\n"
                "LDR     R3, =0x4FB70\n"
                "MOV     R2, #0\n"
                "LDR     R0, [R3]\n"
                "MOV     R1, R7\n"
                "BL      sub_FFC10074\n" //ReceiveMessageQueue
                "LDR     R12, [SP,#0x0]\n"
                "LDR     R2, [R12]\n"
                "CMP     R2, #0x1A\n"
                "BNE     loc_FFCE2E64\n"
                "MOV     R0, R12\n"
                "BL      sub_FFCE114C\n"
                "LDR     R3, =0x4FB6C\n"
                "MOV     R1, #1\n"
                "LDR     R0, [R3]\n"
                "BL      sub_FFC0F8C4\n" //SetEventFlag
                "BL      _ExitTask\n"
                "ADD     SP, SP, #0x14\n"
                "LDMFD   SP!, {R4-R8,PC}\n"
 );
}

void __attribute__((naked,noinline)) sub_FFCE1C34_my(){
 asm volatile(
                "STMFD   SP!, {R4,R5,LR}\n"
                "LDR     R3, =0x4FB6C\n"
                "MOV     R4, R0\n"
                "MOV     R1, #0xE\n"
                "LDR     R0, [R3]\n"
                "BL      sub_FFC0FA60\n" //ClearEventFlag
                "MOV     R1, #0\n"
                "LDRSH   R0, [R4,#4]\n"
                "BL      sub_FFCE11EC\n"
                "MOV     R5, R0\n"
                "LDRSH   R0, [R4,#6]\n"
                "BL      sub_FFCE131C\n"
                "LDRSH   R0, [R4,#8]\n"
                "BL      sub_FFCE13B8\n"
                "LDR     R3, [R4]\n"
                "CMP     R3, #9\n"
                "MOVEQ   R5, #0\n"
                "CMP     R5, #1\n"
                "LDR     R1, =0xFFCE117C\n"
                "MOV     R2, #2\n"
                "BNE     loc_FFCE1CA0\n"
                "LDRSH   R0, [R4,#4]\n"
                "BL      sub_FFE5CDA0\n"
                "LDR     R2, =0x4FB98\n"
                "MOV     R3, #0\n"
                "STR     R3, [R2]\n"
                "B       loc_FFCE1CA4\n"
"loc_FFCE1CA0:\n"
                "BL      sub_FFCE1454\n"
"loc_FFCE1CA4:\n"
                "STRH    R0, [R4,#4]\n"
                "LDRSH   R0, [R4,#6]\n"
                "BL      sub_FFC976B4_my\n"  //---------->
                "BL      sub_FFC99638\n"
                "LDRSH   R0, [R4,#8]\n"
                "MOV     R1, #1\n"
                "BL      sub_FFC99454\n"
                "MOV     R1, #0\n"
                "ADD     R0, R4, #8\n"
                "BL      sub_FFC99518\n"
                "CMP     R5, #1\n"
                "MOV     R1, #2\n"
                "MOV     R2, #0\n"
                "LDMNEFD SP!, {R4,R5,PC}\n"
                "LDR     R3, =0x4FB6C\n"
                "LDR     R0, [R3]\n"
                "LDMFD   SP!, {R4,R5,LR}\n"
                "B       sub_FFC0F8B4\n"
  );
}

void __attribute__((naked,noinline)) sub_FFC976B4_my(){
 asm volatile(
                "STMFD   SP!, {R4,LR}\n"
                "LDR     R3, =0x5388\n"
                "LDR     R2, [R3]\n"
                "MOV     R3, R0,LSL#16\n"
                "CMP     R2, #1\n"
                "MOV     R1, #0x110\n"
                "LDR     R0, =0xFFC97050\n"  //aShutter_c
                "MOV     R4, R3,ASR#16\n"
                "BEQ     loc_FFC976DC\n"
                "BL      sub_FFC03AD0\n"  //DebugAssert
"loc_FFC976DC:\n"
                "MOV     R1, #0x114\n"
                "CMN     R4, #0xC00\n"
                "LDR     R3, =0x3609E\n"
                "LDR     R0, =0xFFC97050\n"  //aShutter_c
                "ADD     R1, R1, #2\n"
                "LDREQSH R4, [R3]\n"
                "LDRNE   R3, =0x3609E\n"
                "CMN     R4, #0xC00\n"
                "STRH    R4, [R3]\n"
                "BNE     loc_FFC97708\n"
                "BL      sub_FFC03AD0\n"  //DebugAssert
"loc_FFC97708:\n"
                "MOV     R0, R4\n"
                "BL      apex2us\n"  //sub_FFC987EC  //---------->
                "BL      sub_FFC96C44\n"
                "TST     R0, #1\n"
                "MOV     R1, #0x118\n"
                "LDR     R0, =0xFFC97050\n"  //aShutter_c
                "LDMEQFD SP!, {R4,PC}\n"
                "LDMFD   SP!, {R4,LR}\n"
                "B       sub_FFC03AD0\n"  //DebugAssert
  );
}
